// 地址选择
class Choose {
    constructor(){
        this.span = document.querySelector(".address span");
        this.div = document.querySelector(".addr");
        this.div1 = document.querySelector(".addr1");

        this.Click(this.div);
        this.Click(this.div1);
    }
    Click(ele){
        var that = this;
        ele.onclick = function(eve){
            var e = eve || window.event;
            var target = e.target || e.srcElement;
            if(target.tagName == "DIV" ){
                that.span.innerHTML = target.innerHTML;
            }
        }
    }
}
new Choose;


// 轮播图
$(".banner").banner({
    // 必传
    img:$(".banner").children(".imgbox").find("a"),
    // 可选，默认为true，true就有功能，false就没有功能
    list:true,
    // 可选，默认为true，true就有功能，false就没有功能
    autoPlay:true,
    // 可选，默认为2000
    delayTime:2000,
    // 可选，默认为200
    moveTime:300
})


// 底价特卖tab切换
$(".sale_top").find("h4").click(function(){
    $(this).addClass("active").siblings().removeClass("active");
    $(".sale_b").children("div").css("display","none").eq($(this).index()).css("display","block");
})


// 滚动出现楼层条
function Scroll() {
    var t = $(".content").offset().top;
    // console.log(t)
    $(document).scroll(function () {
        //    console.log($(document).scrollTop())
        var t1 = $(document).scrollTop();
        if( t1 > t ){
            $(".floor").css("display","block")
        }else{
            $(".floor").css("display","none")
        }

        // 1
        if(t1 >= $(".part_food").offset().top && t1 < $(".part_home").offset().top){
            $(".floor").children(".first").children().addClass("fActive1");
        }else{
            $(".floor").children(".first").children().removeClass("fActive1");
        }

        // 2
        if(t1 >= $(".part_home").offset().top && t1 < $(".part_Intelligence").offset().top){
            $(".floor").children(".second").children().addClass("fActive2");
        }else{
            $(".floor").children(".second").children().removeClass("fActive2");
        }
        // 3
        if(t1 >= $(".part_Intelligence").offset().top && t1 < $(".part_fashion").offset().top){
            $(".floor").children(".three").children().addClass("fActive3");
        }else{
            $(".floor").children(".three").children().removeClass("fActive3");
        }
        // 4
        if(t1 >= $(".part_fashion").offset().top && t1 < $(".part_Beauty").offset().top){
            $(".floor").children(".four").children().addClass("fActive4");
        }else{
            $(".floor").children(".four").children().removeClass("fActive4");
        }
        // 5
        if(t1 >= $(".part_Beauty").offset().top && t1 < $(".adv").offset().top){
            $(".floor").children(".five").children().addClass("fActive5");
        }else{
            $(".floor").children(".five").children().removeClass("fActive5");
        }

    })

    var tb = $(document).scrollTop();
    // 1
    if(tb >= $(".part_food").offset().top && tb < $(".part_home").offset().top){
        $(".floor").children(".first").children().addClass("fActive1");
    }else{
        $(".floor").children(".first").children().removeClass("fActive1");
    }
    // 2
    if(tb >= $(".part_home").offset().top && tb < $(".part_Intelligence").offset().top){
        $(".floor").children(".second").children().addClass("fActive2");
    }else{
        $(".floor").children(".second").children().removeClass("fActive2");
    }
    // 3
    if(tb >= $(".part_Intelligence").offset().top &&tb < $(".part_fashion").offset().top){
        $(".floor").children(".three").children().addClass("fActive3");
    }else{
        $(".floor").children(".three").children().removeClass("fActive3");
    }
    // 4
    if(tb >= $(".part_fashion").offset().top && tb < $(".part_Beauty").offset().top){
        $(".floor").children(".four").children().addClass("fActive4");
    }else{
        $(".floor").children(".four").children().removeClass("fActive4");
    }
    // 5
    if(tb >= $(".part_Beauty").offset().top && tb < $(".adv").offset().top){
        $(".floor").children(".five").children().addClass("fActive5");
    }else{
        $(".floor").children(".five").children().removeClass("fActive5");
    }


    $(".floor").children("p").click(function(){
        $("html").animate({
            scrollTop:$(".content").children().eq($(this).index() + 2).offset().top
        })
    })
    $(".floor").find(".top").click(function(){
        $("html").animate({
            scrollTop:0
        })
    })
}
Scroll();


// 登录成功
class Index{
    constructor(){
        this.login = document.querySelector(".h_login");
        this.wel = document.querySelector(".wel");
        this.logout = document.getElementById("logout");
        this.uName = document.getElementById("userName");
        this.shopcar = document.querySelector(".shopcar");
        this.init();
        this.addEvent();
    }
    init(){
        var that = this;
        this.m = sessionStorage.getItem("userMsg");
        this.m = this.m ? JSON.parse(this.m) : {};
        if(this.m.user){
            this.login.style.display = "none";
            this.wel.style.display = "none";
            this.logout.style.display = "block";
            this.uName.style.display = "block";
            this.uName.innerHTML = this.m.user;
        }
        this.shopcar.onclick = function () {
            if(that.m.user){
                location.href = "pages/shopcar.html"
            }else{
                location.href = "pages/register.html"
            }
        }

    }
    addEvent(){
        this.logout.onclick = function(){
            sessionStorage.removeItem("userMsg");
            location.reload();
        }
    }
}
new Index;

